home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* START.C */
- /* */
- /* This little program shows how easy it is to begin using EnCom! If you */
- /* have ANSI.SYS loaded, this program becomes a nice ANSI terminal -- and */
- /* all in only a few lines of code! */
- /* */
- /* We also have included some sample code (#define GRAPHICS 1) that shows */
- /* how to use the SOURCE_TRACE version of the library when in graphics mode.*/
- /* all you need to do is supply a function that outputs one character to */
- /* the graphics screen and we do the rest for you! If you are not using */
- /* the SOURCE_TRACE version of the library, or are working in text mode, */
- /* then this is not necessary. */
- /****************************************************************************/
- /* #define SOURCE_TRACE 1 */ /* uncomment for source trace! */
- /* #define GRAPHICS 1 */ /* uncomment if using graphics! */
- #include <stdlib.h>
- #include <stdio.h>
- #ifdef __TURBOC__
- #include <graphics.h>
- #endif
- #include "encom.h"
- #include "start.h" /* for taking over keyboard */
-
- /*--------------------------- global variables -----------------------------*/
- PORT Port;
- uchar Encrypt_char, End_flag;
- void graphics_outc(int x, int y, int att, char c);
- void output_ch( int c );
-
- /*********/
- /* ~main */
- /* ********************************************************************/
- /****************************************************************************/
- main( int argc, char *argv[] )
- {
- int port = COM2;
- long baud = 9600L;
- int c, end_flag = 0, echo = 0;
-
- #ifdef GRAPHICS
- int gdriver = DETECT, gmode;
- initgraph(&gdriver, &gmode, "");
- set_dbg_gchar(myoutc);
- setcolor(YELLOW);
- line(0,0,639,479);
- line(0,479,639,0);
- #endif
- if( argc >= 2 )
- {
- switch(argv[1][0])
- {
- case '1': port = COM1; break;
- case '2': port = COM2; break;
- case '3': port = COM3; break;
- case '4': port = COM4; break;
- }
- }
- if( argc >= 3 )
- baud = atol(argv[2]);
- if( com_port_create(port, baud,'N',8,1, 2048, 2048, &Port) < 0 )
- {
- printf("Cannot create COM port");
- return(0);
- }
- init_clock(0x3333);
- init_ctrlc_hdlr();
-
- /*--------- take over 0x23 and 0x1B to suppress CTRL-C and Break ---------*/
- old_vect23 = getvect(0x23);
- old_vect1b = getvect(0x1b);
- setvect(0x23, en_ctrl_c);
- setvect(0x1b, en_ctrl_brk);
-
- printf("\r\nCOM%d at %ld baud\r\n", port + 1, baud);
- printf("ESC to quit - Ctrl-E to toggle Echo\r\n");
- printf("To use another port, type: start [1-4] [baud_rate]\r\n");
- printf("If ANSI.SYS is loaded, this will work as an ANSI terminal\r\n");
- com_232_ctrl(ON, DTR | RTS | OUT2, &Port);
- while( !end_flag )
- {
- if( (c = com_getc(&Port)) != -1 ) /* get any characters */
- output_ch(c);
- if( kbhit() )
- {
- c = getch();
- switch(c) /* get the character */
- {
- case 27: end_flag = 1; break; /* esc to quit */
- case 5: echo = !echo; break; /* ctrl-e is echo */
- case 30: /* translate ctrl-c */
- if ( echo )
- output_ch(3);
- com_putc(3, &Port);
- break;
- default:
- if( echo )
- output_ch(c);
- com_putc(c, &Port);
- break;
- }
- }
- }
- setvect(0x23, old_vect23); /* restore ^C, ^Break */
- setvect(0x1b, old_vect1b);
- end_ctrlc_hdlr();
- end_clock();
- com_port_destroy(&Port);
- #ifdef GRAPHICS
- closegraph();
- #endif
- return(1);
- }
- /*** end of main ***/
-
- /**************/
- /* ~output_ch */
- /* ***************************************************************/
- /* This simple routine outputs a character to the display using good old */
- /* standard output! */
- /****************************************************************************/
- void output_ch( int c )
- {
- fputc(c, stdout), fflush(stdout);
- }
- /*** end of output_ch ***/
-
-
- #ifdef GRAPHICS
- /******************/
- /* ~graphics_outc */
- /* ***********************************************************/
- /* This is a little function that the library will use if in graphics mode. */
- /* If we are in text mode then this is not necessary! */
- /****************************************************************************/
- void graphics_outc(int x, int y, int att, char c)
- {
- char buff[2];
- buff[0] = c, buff[1] = '\0';
- setcolor(att & 0x0f);
- setfillstyle(SOLID_FILL,(att & 0xf0) >> 4);
- bar(x * 8, y * 16, (x * 8) + 7, (y * 16) + 15);
- outtextxy( x * 8, y * 16, buff);
- }
- /*** end of graphics_outc ***/
- #endif
-
- /**** END OF FILE ****/